package com.htu.hdfs;
import java.io.FileNotFoundException;  
import java.io.IOException;  
import java.net.URI;  
import org.apache.hadoop.conf.Configuration;  
import org.apache.hadoop.fs.FileStatus;  
import org.apache.hadoop.fs.FileSystem;  
import org.apache.hadoop.fs.Path;  
public class IteratorListFiles {
	public static void main(String[] args) throws IOException {  
        Configuration conf = new Configuration();  
        String hdfspath = "hdfs://localhost:9000/";  
        FileSystem hdfs = FileSystem.get(URI.create(hdfspath), conf);  
        String watchHDFS = "/";  
  
        iteratorListFile(hdfs, new Path(watchHDFS));  
    }  
    public static void iteratorListFile(FileSystem hdfs, Path path)  
            throws FileNotFoundException, IOException {  
        FileStatus[] files = hdfs.listStatus(path);  
        for (FileStatus file : files) {  
            if (file.isDirectory()) {  
                System.out.println(file.getPermission() + " " + file.getOwner()  
                        + " " + file.getGroup() + " " + file.getPath());  
                iteratorListFile(hdfs, file.getPath());  
            } else if (file.isFile()) {  
                System.out.println(file.getPermission() + " " + file.getOwner()  
                        + " " + file.getGroup() + " " + file.getPath());  
            }  
        }  
    }  
}
